package com.surfilter.massdata.es.core.client.pool;

import org.apache.commons.pool.impl.StackObjectPool;

import com.surfilter.massdata.es.core.client.EsClient;
import com.surfilter.massdata.es.core.client.EsEnv;

public class StackObjectPoolTest {
	public static void main(String[] args) {
		EsEnv esEnv = new EsEnv();
		esEnv.setClusterName("elasticsearch1_hapuer");
		esEnv.setIp("172.31.27.203");
		esEnv.setPort("19310");
		StackObjectPool<EsClient> pool = new StackObjectPool<EsClient>(new PoolableUserFactory(esEnv), 3);
		
		try {
			EsClient user1 = pool.borrowObject();
			EsClient user2 = pool.borrowObject();
			EsClient user3 = pool.borrowObject();
			EsClient user4 = pool.borrowObject();
			EsClient user5 = pool.borrowObject();
			
			pool.returnObject(user1);
			System.out.println("!"+pool.getNumIdle());
			pool.returnObject(user2);
			System.out.println(pool.getNumIdle());
			pool.returnObject(user3);
			System.out.println(pool.getNumIdle());
			pool.returnObject(user4);
			pool.returnObject(user5);
			System.out.println(pool.getNumIdle());
			System.out.println(pool.borrowObject());
			System.out.println(pool.borrowObject());
			System.out.println(pool.borrowObject());
			System.out.println(pool.borrowObject());
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}
}
